//
//  MQTTClientModel.h
//  Rinnai
//
//  Created by 朱天聪 on 2018/5/10.
//  Copyright © 2018年 Hadlinks. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ZCBaseRequestManager.h"
@protocol MQTTClientManagerDelegate <NSObject>
@optional
-(void)MQTTClientManger_handleMessage:(NSData *)data onTopic:(NSString *)topic retained:(BOOL)retained;


@end

typedef void(^SLMQTTHeartBlock)(SLLockModel *bridgeModel,BOOL isOnline);
@interface SLMqttManager : NSObject
@property (nonatomic, assign)BOOL isConnected;
@property (nonatomic, weak) id <MQTTClientManagerDelegate> delegate;

+(instancetype)sharedInstance;

-(void)connectAwsMqttServer:(void(^)(BOOL isConnect,NSError *error))finish;
-(void)disConnect;
-(void)reConnect;
-(void)registerShadow;
@property (nonatomic, copy)SLMQTTHeartBlock heartBlock;
/*
 订阅主题
 
 @param topic 主题
 */
typedef void (^SubscribeTopicHandler)(NSString *topic, BOOL success);

//订阅主题
-(void)subscribeTopic:(NSString *)topic messageBlock:(void(^)(id data))messageBlock;

/*
 取消订阅
 
 @param topic 主题
 */
-(void)unsubscribeTopic:(NSString *)topic;

/*
 发布消息
 */
-(void)sendDataToTopic:(NSString *)topic params:(NSDictionary *)params;

//检测设备是否在线 - 单次
-(void)checkBridgeIsOnlineOnce:(void(^)(BOOL isOnLine))finish;

//检测设备是否在线 - 持续检查
-(void)checkBridgeOnlineStatus:(void(^)(SLLockModel *model,BOOL isOnline))finish;

#pragma mark -
#pragma mark - ================<MQTT协议封装>===============
-(void)requestMqttApiWith:(NSString *)cmd params:(NSDictionary *)params finish:(ZCRequiredFinished)finish;

-(void)startUpdateFirmwareWith:(NSData *)firmwareData finish:(SLUpdateFirmwareBlock)finish;
@end
